package cc.fs.kotlinproject

import android.animation.ValueAnimator
import android.app.Activity
import android.content
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Message
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.animation.AnimationUtils
import android.view.animation.LinearInterpolator
import android.view.animation.ScaleAnimation
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import butterknife.bindView
import cc.fs.kotlinproject.network
import cc.fs.kotlinproject.network.OkHttpUtil
import cc.fs.kotlinproject.utlis.getIntent
import cc.fs.kotlinproject.utlis.show
import com.squareup.picasso.Picasso
import java.util.*
import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantLock
import javax.xml.transform.Result

public class MainActivity : BaseActivity() {

    companion object{
        fun start(context: Activity){
            val intent = getIntent<MainActivity>(context)
            context.startActivityForResult(intent,101)
        }
    }

    val button: Button by bindView(R.id.button)
    val button2: Button by bindView(R.id.button2)
    val name: TextView by bindView(R.id.name)
    val password: TextView by bindView(R.id.password)
    val image: ImageView by bindView(R.id.image)
    val list = listOf<String>();

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var shackAnimation = AnimationUtils.loadAnimation(this, R.anim.shack);

        button.setOnClickListener {
            Picasso.with(this).load("http://square.github.io/picasso/static/sample.png").placeholder(R.mipmap.ic_launcher).into(image)
            Thread({
                OkHttpUtil.get("https://www.baidu.com/index.php?tn=20041099_oem_dg&ch=33", {
                    rlt ->
                    Log.e(" --- ", "   " + rlt)
                })
            }).start();
            val list: MutableList<String> = LinkedList<String>()
            list.add("a")
            list.add("b")
            list.add("c")

            val map:MutableMap<String,String> = LinkedHashMap<String,String>()
            map.put("1","a")
            map.put("2","b")
            map.put("3","c")


            for(index in list){
                print(index +"---")
            }

            for((k,v) in map){
                print(k +"---"+"  y")
            }

            when (valid()) {
                0 -> {
                    name.startAnimation(shackAnimation)
                    Toast.makeText(this, "名字不少于5个", Toast.LENGTH_SHORT).show()
                }
                1 -> {
                    password.startAnimation(shackAnimation)
                    Toast.makeText(this, "密码不少于5个", Toast.LENGTH_SHORT).show()
                }
                else -> {
                    Toast.makeText(this, "ok", Toast.LENGTH_SHORT).show()
                }
            }
        }

        button2.setOnClickListener {
            FrashActivity.start(this)
        }
    }

    fun valid(): Int {
        if (name.getText().length() < 5) return 0;
        if (password.length() < 5) return 1;
        return 2;
    }

    override fun handler(message: Message) {
    }

}



